//! file: erase.cpp

#include <iostream>
#include <string>
using namespace std;
#include "gtest/gtest.h"
#include "List02.hpp"

TEST(eraseTest, position)
{
	int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
	List<int> lst(arr, arr + sizeof(arr) / sizeof(int));
	List<int>::iterator it = lst.begin();

	++it;
	it = lst.erase(it);
	EXPECT_EQ(*it, 3);
	EXPECT_EQ(*--it, 1);
	EXPECT_EQ(lst.size(), 8u);
}

TEST(eraseTest, ranges)
{
	int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
	List<int> lst(arr, arr + sizeof(arr) / sizeof(int));
	List<int>::iterator it1, it2;

	it1 = lst.begin();
	++it1;
	it2 = lst.end();
	--it2;

	it2 = lst.erase(it1, it2);
	EXPECT_EQ(lst.size(), 2u);
	EXPECT_EQ(*lst.begin(), 1);
	EXPECT_EQ(*--lst.end(), 9);
	EXPECT_EQ(*it2, 9);
}

TEST(clearTest, empty)
{
	List<int> lst;

	lst.clear();
	EXPECT_EQ(lst.size(), 0u);

}

TEST(clearTest, nonEmpty)
{	
	int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
	List<int> lst(arr, arr + sizeof(arr) / sizeof(int));

	EXPECT_EQ(lst.size(), 9u);
	lst.clear();
	EXPECT_EQ(lst.size(), 0u);
}
